import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;


public class Main {
	static ConcurrentLinkedQueue<Mash> work;
	static Maschen allMash; 
	static Main me; 
	static XmlToGraphParser parser;
	static Graph graph;

	public static void main(String argv[]){
		me = new Main();

		parser = new XmlToGraphParser();
//		File f = new File("/home/govinda/uni/NP/projekt/unser_bsp.xml");
		File f = new File("/home/govinda/uni/NP/projekt/testsuite/crack/germany.xml");
//		File f = new File("/home/govinda/uni/NP/projekt/testsuite/speed/graph00.xml");
//		File f = new File("/home/govinda/uni/NP/projekt/testsuite/speed/graph10.xml");
		graph = parser.getGraph(f);//new ConcurrentHashMap<Integer, Knoten>();
		// parser supplies a parsed Map for "allMash" and "work"
		System.err.println(graph);
		allMash = new Maschen(graph);
		work = allMash.getMaschen();
		int many = 5;

		Thread[] t = new Thread[many];

		for(int i = 0; i < many; i++){
			t[i] = new Thread(new Worker());
			t[i].start();
		}

		for(int i = 0; i < many; i++){
			try {
				t[i].join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}		
		allMash.delEmpty();
		System.out.println("maschen: " + allMash);
		System.out.println("Anzahl Stromnetze: " + allMash.getMaschen().size());
	}




	//public class Worker implements Runnable{
	//	
	//		@Override
	//		public void run() {
	//			while (!Thread.interrupted() && !work.isEmpty()){
	//				Knoten akt = work.pollFirst();  //krit
	//				if(akt == null) break;
	//				List<Knoten> vorList=akt.getVorganger();
	//				
	//				for(Knoten pre : vorList){
	//					List<Knoten> mashList= new CopyOnWriteArrayList<Knoten>();
	//					Mash preMash= pre.getMash();
	//					for(Knoten knBack: preMash.getkList()){
	//						if(!vorList.contains(knBack)){
	//							mashList.add(knBack);
	//							
	//						}
	//					}
	//					if (!mashList.isEmpty()){
	//					preMash.removeKnList(mashList);
	//					Mash neu = new Mash(pre.getCapacity(),mashList);
	//					allMash.add(neu);
	//					}
	//				}
	//			}
	//		}
	//
	//	}
}